package dataprovider;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import listdata.ListData;
import model.Customer;

import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.IModel;

import common.CommonUtil;

public class CustomerDataProvider implements IDataProvider {
	
	private static final long serialVersionUID = 1L;

	private List<Customer> list = null;
	
	public CustomerDataProvider(){
		list = ListData.fillCustomerList();
	}
	
	public void detach() {
		// TODO Auto-generated method stub
		
	}

	@SuppressWarnings("rawtypes")
	public Iterator iterator(int first, int count) {
		if(CommonUtil.isNotEmpty(list))
			return list.subList(first, first+count).iterator();
		
		return Collections.EMPTY_LIST.iterator();
	}

	public IModel model(Object object) {
		return new DetachableCustomerModel((Customer)object);
	}

	public int size() {
		if(CommonUtil.isNotEmpty(list))
			return list.size();
			
		return 0;
	}

}
